package qqclient.view;

import qqclient.service.FileClientService;
import qqclient.service.MessageClientService;
import qqclient.service.UserClientService;
import qqclient.utility.Utility;

/**
 * @author 王艺锡
 * @version 1.0
 * 菜单主页面
 */
public class QQView {
    private String choose = "";
    private boolean flag = true;
    private UserClientService userClientService = new UserClientService();
    private MessageClientService messageClientService = new MessageClientService();
    private FileClientService fileClientService = new FileClientService();

    public static void main(String[] args) {
        new QQView().mainMenu();
    }


    //主菜单
    private void mainMenu() {
        while (flag) {
            System.out.println("============欢迎登录网络通讯系统============");
            System.out.println("\t\t1.登录系统");
            System.out.println("\t\t0.退出系统");
            System.out.print("请输入你的选择:>");
            choose = Utility.readString(1);

            switch (choose) {
                case "1":
                    System.out.print("请输入用户号:>");
                    String userid = Utility.readString(50);
                    System.out.print("请输入密 码:>");
                    String pwd = Utility.readString(50);

                    if (userClientService.checkUser(userid, pwd)) {//如果用户号和密码正确
                        System.out.println("登录成功,欢迎" + userid + "用户");

                        while (flag) {
                            System.out.println("\n============网络通讯二级菜单(" + userid + ")============");
                            System.out.println("\t\t1.显示在线用户列表");
                            System.out.println("\t\t2.群发消息");
                            System.out.println("\t\t3.私聊消息");
                            System.out.println("\t\t4.发送文件");
                            System.out.println("\t\t0.退出系统");
                            System.out.print("请选择:>");
                            choose = Utility.readString(1);

                            switch (choose) {
                                case "1":
                                    userClientService.getOnlineFriendList();
                                    break;
                                case "2":
                                    System.out.print("请输入想要群发的消息: ");
                                    String s = Utility.readString(100);
                                    messageClientService.massChat(userid,s);
                                    break;
                                case "3":
                                    System.out.print("请输入想要聊天的用户号(在线): ");
                                    String receiver = Utility.readString(50);
                                    System.out.print("请输入想要说的话: ");
                                    String content = Utility.readString(100);
                                    messageClientService.PrivateChat(userid,receiver,content);
                                    break;
                                case "4":
                                    System.out.print("请输入接收者用户id:");
                                    receiver = Utility.readString(50);
                                    System.out.print("请输入你要发送的文件路径:");
                                    String srcPath = Utility.readString(100);
                                    System.out.print("请输入接收者接收文件的路径:");
                                    String destPath = Utility.readString(100);
                                    fileClientService.sendFile(userid,receiver,srcPath,destPath);
                                    break;
                                case "0":
                                    userClientService.exitClient();
                                    flag = false;
                                    break;
                                default:
                                    System.out.println("输入错误，请重新输入!");
                                    break;
                            }


                        }

                    } else {//如果用户号和密码错误
                        System.out.println("用户号或密码错误，请重新输入!");
                    }
                    break;
                case "0":
                    flag = false;
                    System.out.println("退出系统!");
                    break;
                default:
                    System.out.println("选择错误，请重新选择!");
                    break;
            }
        }
    }
}
